import React from 'react';
import { FormContainer } from './FormContainer';
import FormItem from './FormItem';
import FormBlock from './FormBlock';

const Form4 = props => {
    const {
        form,
        initialFormInfo: { talentCode, recruitTalentWorks = [], workExperience }
    } = props;
    const { required = true, ...otherProps } = props; // required为true和false判断走2套校验规则
    const [experienceRequired, setExperienceRequired] = React.useState(false);
    const [hideBlock, setHideBlock] = React.useState(true);
    const formInfoList = [
        {
            label: '起止时间',
            prop: 'dateRange',
            type: 'dateRange'
        },
        {
            label: '工作单位',
            prop: 'organize',
            type: 'input'
        },
        {
            label: '行业/主营业务',
            prop: 'industry',
            type: 'select',
            dictCode: 'industryType'
        },
        {
            label: '职位',
            prop: 'post',
            type: 'input'
        },
        {
            label: '离职原因',
            prop: 'reason',
            type: 'input'
        },
        {
            label: '直接上级',
            prop: 'approveName',
            type: 'input'
        },
        {
            label: '手机号码',
            prop: ['areaCode', 'approvePhone'],
            type: 'telephone'
        }
    ];
    const blockProps = {
        ...otherProps,
        form,
        parentFieldData: recruitTalentWorks,
        parentField: 'recruitTalentWorks',
        formInfoList,
        titleText: '工作经历',
        addButtonText: '+添加工作经历',
        id: 'form4',
        talentCode
    };
    React.useEffect(() => {
        const workExperienceVal = form.getFieldValue('workExperience');
        setExperienceRequired(workExperienceVal === 1);
        setHideBlock(workExperienceVal !== 1);
    }, [form.getFieldValue('workExperience'), workExperience]);
    return (
        <>
            <FormBlock hideBlock={hideBlock} disabled={hideBlock} required={experienceRequired} {...blockProps}>
                <FormContainer>
                    <FormItem
                        required={required}
                        label="工作经验"
                        prop="workExperience"
                        type="radio"
                        options={[
                            { dictName: '有', dictValue: 1 },
                            { dictName: '无（应届生）', dictValue: 0 }
                        ]}
                        {...otherProps}
                    />
                </FormContainer>
            </FormBlock>
        </>
    );
};

export default React.memo(Form4);
